package com.v2future.sjt.collegecheckingattendance.leave.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;

import com.v2future.sjt.collegecheckingattendance.R;
import com.v2future.sjt.collegecheckingattendance.leave.CancelLeaveActivity;
import com.v2future.sjt.collegecheckingattendance.leave.bean.WaitApproveBean;
import com.v2future.sjt.collegecheckingattendance.utils.WidgetUtil;

import java.util.List;

/**
 * Created by minnie on 16/3/2.
 */
public class CancelLeaveAdapter extends BaseAdapter {

    List<WaitApproveBean> dataList;
    Context mContext;
    CancelBtnClickListener listener;

    public CancelLeaveAdapter(List<WaitApproveBean> dataList, Context mContext) {
        this.dataList = dataList;
        this.mContext = mContext;
        listener = (CancelLeaveActivity)mContext;
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public Object getItem(int position) {
        return dataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        WaitApproveBean bean = dataList.get(position);
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.listitem_cancel_leave, null);
            holder = new ViewHolder();
            holder.timeTv = (TextView) convertView.findViewById(R.id.tv_time);
            holder.typeTv = (TextView) convertView.findViewById(R.id.tv_leave_type);
            holder.statusTv = (TextView) convertView.findViewById(R.id.tv_status);
            holder.applyDateTv = (TextView) convertView.findViewById(R.id.tv_apply_date);
            holder.cancelBtn = (Button) convertView.findViewById(R.id.btn_cancel_leave);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        WidgetUtil.setText(holder.timeTv, bean.getActionTime());
        WidgetUtil.setText(holder.applyDateTv, bean.getActionStTime());
        WidgetUtil.setText(holder.statusTv, bean.getSubmitStatusName());
        WidgetUtil.setText(holder.typeTv, bean.getActionTypeName());
        holder.cancelBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.cancelBtnClick(position);
            }
        });
        return convertView;
    }

    public class ViewHolder {
        TextView timeTv;
        TextView typeTv;
        TextView statusTv;
        TextView applyDateTv;
        Button cancelBtn;
    }

    public interface CancelBtnClickListener{
        public void cancelBtnClick(int position);
    }
}
